<?php
class Aclplugin extends Zend_Controller_Plugin_Abstract {
  private $_acl = null;
 
  public function __construct(Zend_Acl $acl) {
    $this->_acl = $acl;
  }
 
  public function preDispatch(Zend_Controller_Request_Abstract $request) {
      
//      print_r($request->getParams());die();
      
      
    $role = (Zend_Auth::getInstance()->hasIdentity())
          ? 'user'
          : 'guest';
          
          
    $resource = $request->getControllerName();
    $action = $request->getActionName();
    
    
    
    try{
    
        if(!$this->_acl->isAllowed($role, $resource, $action)) {
        	$Front = Zend_Controller_Front::getInstance();
        	$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
            $redirector->gotoUrl('auth/login');
        }
    }
    catch (Exception $e)
    {
        
        
        $loggerACL = Zend_Registry::get('loggerACL');
        $loggerACL->log("Resource error :: Role: " . $role . "      Resource: " . $resource . "      Action: " . $action, Zend_Log::CRIT);
    
        $Front = Zend_Controller_Front::getInstance();
        $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
        $redirector->gotoUrl('/');
    }    
    
    
    
 
  }
}